package com.jkdroid.maya.util;

import android.content.Context;
import android.widget.Toast;

/**
 * Toast工具类
 * @author guanzhihao
 * @date   2015年12月14日
 *
 */
public class ToastUtils {

	/**
	 * 显示一个短toast
	 * @param context
	 * @param charSequence
	 */
    public static void show(Context context, CharSequence charSequence){
        show(context, charSequence, false, Toast.LENGTH_SHORT);
    }

	/**
	 * 显示一个短toast
	 * @param context
	 * @param resId
	 */
    public static void show(Context context, int resId){
        show(context, resId, false, Toast.LENGTH_SHORT);
    }

	/**
	 * 显示一个短长
	 * @param context
	 * @param charSequence
	 */
    public static void showLong(Context context, CharSequence charSequence){
    	show(context, charSequence, false, Toast.LENGTH_LONG);
    }

	/**
	 * 显示一个短长
	 * @param context
	 * @param resId
	 */
    public static void showLong(Context context, int resId){
    	show(context, resId, false, Toast.LENGTH_LONG);
    }

	/**
	 * 立刻显示一个短toast
	 * @param context
	 * @param charSequence
	 */
    public static void showImmediately(Context context, CharSequence charSequence){
        show(context, charSequence, true, Toast.LENGTH_SHORT);
    }

	/**
	 * 立刻显示一个短toast
	 * @param context
	 * @param resId
	 */
    public static void showImmediately(Context context, int resId){
        show(context, resId, true, Toast.LENGTH_SHORT);
    }   

	/**
	 * 立刻显示一个长toast
	 * @param context
	 * @param charSequence
	 */
    public static void showLongImmediately(Context context, CharSequence charSequence){
    	show(context, charSequence, true, Toast.LENGTH_LONG);
    }

	/**
	 * 立刻显示一个长toast
	 * @param context
	 * @param resId
	 */
    public static void showLongImmediately(Context context, int resId){
    	show(context, resId, true, Toast.LENGTH_LONG);
    }

    private static void show(Context context, CharSequence charSequence, boolean immediately, int duration){
        if(context == null){
            return;
        }
        
        if(immediately && mToast != null){
        	mToast.cancel();
        }
        
        mToast = Toast.makeText(context, charSequence, duration);
        mToast.show();
    }
 
    private static void show(Context context, int id, boolean immediately, int duration){
        if(context == null){
            return;
        }
        
        if(immediately && mToast != null){
        	mToast.cancel();
        }
        
        mToast = Toast.makeText(context, id, duration);
        mToast.show();
    }
    
    private static Toast mToast;

    private ToastUtils(){}
}
